//
//  ZJCRImageViewAndLabelView.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/6/30.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJCRImageViewAndLabelView.h"
#import "StudyCoureVideoViewController.h"
@interface ZJCRImageViewAndLabelView ()
/** 图片 */
@property (nonatomic, strong) UIImageView *imageview;
/** cell类型图片 */
@property (nonatomic, strong) UIImageView *typeImageView;
/** 题目 */
@property (nonatomic, strong) UILabel *titleLabel;
@end

@implementation ZJCRImageViewAndLabelView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self addSubview:self.imageview];
        [self addSubview:self.typeImageView];
        [self addSubview:self.titleLabel];
        
        self.imageview.sd_layout
        .topSpaceToView(self, 0)
        .leftSpaceToView(self, 0)
        .rightSpaceToView(self, 0)
        .heightIs(100 * [UIScreen zj_screenHScale]);
        
        self.typeImageView.sd_layout
        .widthIs(40 * [UIScreen zj_screenHScale])
        .heightEqualToWidth()
        .centerXEqualToView(self.imageview)
        .centerYEqualToView(self.imageview);
        
        
        self.titleLabel.sd_layout
        .topSpaceToView(self.imageview, 4 * [UIScreen zj_screenHScale])
        .leftEqualToView(self.imageview)
        .widthIs(self.width)
        .heightIs(10);
        
        UITapGestureRecognizer *tapGester = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(action_tapGester)];
        [self addGestureRecognizer:tapGester];
        
    }
    return self;
}


- (void)action_tapGester{
    if (self.delegate) {
        [self.delegate ZJCourseRecommendViewDelegate_model:self.model];
    }

}


#pragma mark - Setter

- (void)setModel:(ZJStudySpacialDetailModel *)model{
    _model = model;
    [self.imageview sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",BASEIMAGEURL,model.IMAGEPHOTO_THUMBURL]] placeholderImage:PlaceholderImage];
    self.titleLabel.text = model.NAME;
    
    self.titleLabel.sd_layout
    .topSpaceToView(self.imageview, 4 * [UIScreen zj_screenHScale])
    .leftEqualToView(self.imageview)
    .widthIs(self.width)
    .heightIs([self.titleLabel getLableSizeWithMaxWidth:self.width].height);
    [self.titleLabel updateLayout];
}

#pragma mark - Getters
- (UIImageView *)imageview{
    if (_imageview == nil){
        _imageview = [UIImageView new];
        _imageview.contentMode = UIViewContentModeScaleAspectFill;
        _imageview.clipsToBounds = YES;
    }
    return _imageview;
}
- (UIImageView *)typeImageView{
    if (_typeImageView == nil){
        _typeImageView = [UIImageView new];
        _typeImageView.contentMode = UIViewContentModeCenter;
    }
    return _typeImageView;
}

- (UILabel *)titleLabel{
    if (_titleLabel == nil){
        _titleLabel = [UILabel new];
        _titleLabel.textColor = [UIColor textBlackColor];
        _titleLabel.font = [UIFont titleTextFont];
        _titleLabel.numberOfLines = 2;
        _titleLabel.lineSpace = 4 * [UIScreen zj_screenHScale];
        _titleLabel.characterSpace = 1;
    }
    return _titleLabel;
}



@end
